package com.zwg.mode.mvp

import com.zwg.mode.mvc.API


/**
 * Author wengang
 * Time 2024/5/26
 */
class MVPUserModel {

    //常量
    companion object {
        const val STATE_LOGIN_LOADING = 0
        const val STATE_LOGIN_SUCCESS = 1
        const val STATE_LOGIN_FAILED = 2
    }

    private val api by lazy {
        API()
    }

    private val ranDom = java.util.Random()

    /**
     * 进行登录操作
     */
    fun doLogin(accout: String, password: String, bloc: (Int) -> Unit) {
        bloc.invoke(STATE_LOGIN_LOADING)
        //开始去调用登录的API
        //有结果，此操作为耗时操作
        //0,1,不包含2
        val randomValue = ranDom.nextInt(2)
        if (randomValue == 0) {
            bloc.invoke(STATE_LOGIN_SUCCESS)
        } else {
            bloc.invoke(STATE_LOGIN_FAILED)
        }
    }

    //lamban表达式
    fun checkUserState(account: String, block: (Int) -> Unit) {
        //0表示该用户已经注册
        //1表示该账号没有进行注册
        block.invoke(ranDom.nextInt(2))
    }


    interface OnDoLoginStateChange {
        fun onLoading()

        fun onLoginSuccess()

        fun onLoginFailed()
    }
}